/*
 * @Descripttion:
 * @Author: zhangchong zc16607@gmail.com
 * @Date: 2022-12-30 11:56:06
 * @LastEditors: zhangchong zc16607@gmail.com
 * @LastEditTime: 2023-05-22 16:11:06
 */
const Components = require("unplugin-vue-components/webpack");
const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");
const IconsResolver = require("unplugin-icons/resolver");

module.exports = {
  // publicPath: '/codes/',
  configureWebpack: {
    devtool: "source-map",
    plugins: [
      // elementPlus组件自动按需导入
      Components({
        resolvers: [
          IconsResolver({
            prefix: false, // 不要前缀
            enabledCollections: ["ep"], // 启用的svg图标集合
          }),
          ElementPlusResolver(),
        ],
      }),
      // 自动按需导入elementPlus图标
      require("unplugin-icons/webpack")({ autoInstall: true }),
    ],
  },
  chainWebpack: (config) => {
    config.plugin("html").tap((args) => {
      args[0].title = "首页";
      return args;
    });
  },
  pluginOptions: {
    electronBuilder: {
      chainWebpackMainProcess: (config) => {
        config.output.filename((file) => {
          if (file.chunk.name === "index") {
            return "background.js";
          } else {
            return "[name].js";
          }
        });
      },
      transpileDependencies: true,
      builderOptions: {
        appId: "com.365ysx.app",
        //artifactName: "${name}_${version}_${os}_${arch}.${ext}",
        artifactName: "业财税融合大数据应用系统.${ext}",
        productName: "业财税融合大数据应用系统",
        copyright: "@ 湖南安信中德安普 Copyright 2023",
        generateUpdatesFilesForAllChannels: true,
        directories: {
          // output:"builder",
          // app: "dist_electron/codes/"
        },
        nsis: {
          allowToChangeInstallationDirectory: true,
          createDesktopShortcut: "always",
          installerLanguages: "zh_CN",
          language: "2052",
          oneClick: false,
          perMachine: true,
          runAfterFinish: false,
        },
        asar: true,
        win: {
          target: "nsis", // 打包为免安装应用，可以改为portable,但是启动要十几秒
          icon: "./build/icon.ico",
          requestedExecutionLevel: "asInvoker", // 启动模式，普通用户或管理员权限
          verifyUpdateCodeSignature: false,
        },
        mac: {
          category: "public.app-category.utilities",
          target: [
            {
              arch: ["arm64", "x64"],
              target: "default", // Squirrel.Mac requires the zip target. Reference: https://www.electron.build/auto-update#quick-setup-guide
            },
          ],
        },
        // 第二中复制静态资源，到resources的方式，不是压缩到app.asar 中
        // extraResources: {
        //   // 拷贝静态文件到指定位置,否则打包之后出现找不到资源的问题.将整个resources目录拷贝到 发布的根目录下
        //   from: 'public/codes/',
        //   to: './'
        // }
        // files: [
        //   "codes/*",
        //   "background.js"],
      },
      preload: "./src/preload.js",
    },
  }, // Reference: https://www.electron.build/configuration/configuration
  runtimeCompiler: true,
};
